/*
** xfunctions2.c for  in /home/gomes_m//svn/tek2/zappy-2016-gomes_m/reseau/server
** 
** Made by mickael gomes
** Login   <gomes_m@epitech.net>
** 
** Started on  Tue Jun 25 17:55:42 2013 mickael gomes
** Last update Tue Jul 23 14:21:29 2013 mickael gomes
*/

#include        <sys/types.h>
#include	<sys/socket.h>
#include	<sys/select.h>
#include	<sys/time.h>
#include	<stdlib.h>
#include	<unistd.h>
#include	"struct.h"
#include	"prototypes.h"

int	        xaccept(t_socket *socket)
{
  int		fd;

  fd = accept(socket->sock, socket->cast_sin_client, socket->cast_client_len);
  return (fd);
}

int		xselect(int fds, fd_set *r, fd_set *w, fd_set *ex, struct timeval *tv)
{
  if (select(fds, r, w, ex, tv) == -1)
    my_putstr(2, "Select Error.\n", 1);
  return (1);
}

void		*xmalloc(int size)
{
  void		*ptr;

  if ((ptr = malloc(size)) == NULL)
    my_putstr(2, "Malloc Error.\n", 1);
  return (ptr);
}

void		xclose(int fd)
{
  if (close(fd) == -1)
    my_putstr(2, "Close Error.\n", 1);
}

int		xwrite(int fd, char *c, int size)
{
  int		len;

  if ((len = write(fd, c, size)) <= 0)
    exit(EXIT_FAILURE);
  return (len);
}
